package com.tech.connect.huanzhewan;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.ksy.common.utils.BaseAdapter;
import com.ksy.common.utils.BaseHolder;
import com.ksy.common.view.HLineDivider;
import com.tech.connect.R;
import com.tech.connect.activity.CityChooseActivity;
import com.tech.connect.fragment.BaseFragment;

import java.util.ArrayList;
import java.util.List;

public class HuanZheWanHuHuanShenFenFragment extends BaseFragment {


    private RecyclerView recycler;
    private List<String> allList = new ArrayList<>();
    private BaseAdapter<String, BaseHolder> adapter;

    @Override
    protected View onCreateView(LayoutInflater inflater) {
        View inflate = inflater.inflate(R.layout.fragment_huanzhewan_huhuanshenfen, null);
        return (inflate);
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initView(view);
        initAdapter();
    }


    private void initView(View view) {
        view.findViewById(R.id.ivBack).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                activity.onBackPressed();
            }
        });
        TextView tvCity = view.findViewById(R.id.tvCity);
        tvCity.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                jump2Activity(CityChooseActivity.class);
            }
        });
        view.findViewById(R.id.tvPublish).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                jump2Activity(PublishChangeInfoActivity.class);
            }
        });
        view.findViewById(R.id.llXiongYinShaoNian).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(activity, HuanZheWanHuHuanShenFenActivity.class);
                intent.putExtra("tagTitle", "雄鹰少年");
                jump2Activity(intent);
            }
        });
        view.findViewById(R.id.llShiShengBianShen).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(activity, HuanZheWanHuHuanShenFenActivity.class);
                intent.putExtra("tagTitle", "师生变身");
                jump2Activity(intent);
            }
        });
        view.findViewById(R.id.llZhangGuiJiaoShou).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(activity, HuanZheWanHuHuanShenFenActivity.class);
                intent.putExtra("tagTitle", "掌柜交手");
                jump2Activity(intent);
            }
        });
        view.findViewById(R.id.llZhiYeTiYan).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(activity, HuanZheWanHuHuanShenFenActivity.class);
                intent.putExtra("tagTitle", "职业体验");
                jump2Activity(intent);
            }
        });
        view.findViewById(R.id.llQiTa).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(activity, HuanZheWanHuHuanShenFenActivity.class);
                intent.putExtra("tagTitle", "其他");
                jump2Activity(intent);
            }
        });
        recycler = view.findViewById(R.id.recycler);
        recycler.setLayoutManager(new LinearLayoutManager(activity, LinearLayoutManager.VERTICAL, false) {
            @Override
            public boolean canScrollVertically() {
                return false;
            }
        });
        recycler.addItemDecoration(new HLineDivider());
    }

    private void initAdapter() {
        if (adapter == null) {
            adapter = new BaseAdapter<String, BaseHolder>(R.layout.item_layout_huhuanshenfen, allList, 16) {
                @Override
                protected void convert(BaseHolder helper, int position) {
                    ImageView ivHead = helper.getView(R.id.ivHead);
                    TextView tvName = helper.getView(R.id.tvName);
                    TextView tvTag = helper.getView(R.id.tvTag);
                    TextView tvDate = helper.getView(R.id.tvDate);
                    TextView tvExtra = helper.getView(R.id.tvExtra);
                    tvTag.setText("少年雄鹰");
                }
            };
            adapter.setOnItemClickListener(new BaseAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(View view, int position) {
                    jump2Activity(HuanZheWanShenFenViewActivity.class);
                }
            });
            recycler.setAdapter(adapter);
        }
        adapter.notifyDataSetChanged();
    }

}
